﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.ElementImplementGrid = function (config) {

    Ext.apply(this, config);

    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/FlowElementViewService.aspx?Action=SearchImplement'

        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Description', 'FlowFlie', 'OrgRange', 'Details', 'Equip', 'Require', 'PersonNumber', 'EchelonNumber', 'StartTime', 'Status', 'EndTime']
        }),
        remoteStore: true
    });

    this.store = fileStore;

    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    },{
        header: '警力及任务部署',
        dataIndex: 'OrgRange',
        width: 300,
        renderer: function qtips(val, p, record) {
            p.attr = 'style="white-space:normal;"';
            return String.format(
                '<b>梯队：</b>{0}&nbsp&nbsp&nbsp<b>部门：</b>{1}<br/><br/><b>人数：</b>{2}<br/><br/><b>任务：</b>{3}<br/><br/><b>装备：</b>{4}<br/>',
               record.data.EchelonNumber, val, record.data.PersonNumber, record.data.Details, record.data.Equip);
        }
    },{
        header: '状态',
        dataIndex: 'Status',
        width: 200,
        renderer: function qtips(val, p, record) {
            return String.format(
                '<b>开始时间：</b>{0}<br/><br/><b>结束时间：</b>{1}<br/><br/><b>当前状态：</b>{2}',
               record.data.StartTime, record.data.EndTime, val);
        }
    }, {
        header: '要求',
        dataIndex: 'Require',
        width: 50,
        renderer: function qtips(val, p, record) {
            return '<span style="display:table;width=100%;" qtip=\'<div>' + val + '</div>\'>要求</span>'
        }

    }];
    FantastPlatform.UI.ElementImplementGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
}

Ext.extend(FantastPlatform.UI.ElementImplementGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.ElementImplementGrid.superclass.onRender.call(this, ct, position);
    },
    onAddElementImplementClick: function (flowId,level) {
        var id = GUID();
        currtWind = openWind('../EmergencyFlow/ElementImplementForm.aspx?flowId=' + flowId + '&level=' + level, id, '执行任务', 650, 450, null);
    },
    //修改
    onEditElementImplementClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
              //  if (node[0].get('PoliceMan') == policemanNumber) {
                    var fId = node[0].get('Id');
                    var id = GUID();

                    currtWind = openWind('../EmergencyFlow/ElementImplementForm.aspx?id=' + fId, id, '编辑执行任务', 650, 450, null);
             //   } else {
             //       showErrorMessage("操作失败", "只能自己添加的数据进行编辑", "");          
              //  } 
            }
        }
    }, 
    onSearchClick: function (flowId) {
        var id = GUID();
        currtWind = openWind('../EmergencyFlow/ElementImplementSearchForm.aspx?id=' + flowId, id, '查询', 360, 170, 'new_tab');
    }
    ,     
    //刷新
    onUpdataElementImplementClick: function (flowId) {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: this.url };
        this.store.load({ params: { flowId: flowId, start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }

});
    
